
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/19/2011 17:29:14
-- Generated from EDMX file: C:\Users\Kevin Boosten\Documents\Visual Studio 2010\Projects\BackEndSystemWebTv\BackEndSystemWebTv\BackEndSystemWebTv\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [webtvdatabase];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AutorisatieSociaalMedium]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Autorisaties] DROP CONSTRAINT [FK_AutorisatieSociaalMedium];
GO
IF OBJECT_ID(N'[dbo].[FK_GebruikerAutorisatie]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Autorisaties] DROP CONSTRAINT [FK_GebruikerAutorisatie];
GO
IF OBJECT_ID(N'[dbo].[FK_GebruikerLog]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Logs] DROP CONSTRAINT [FK_GebruikerLog];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Autorisaties]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Autorisaties];
GO
IF OBJECT_ID(N'[dbo].[Gebruikers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Gebruikers];
GO
IF OBJECT_ID(N'[dbo].[Logs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Logs];
GO
IF OBJECT_ID(N'[dbo].[SociaalMediums]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SociaalMediums];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Gebruikers'
CREATE TABLE [dbo].[Gebruikers] (
    [GebruikersId] int IDENTITY(1,1) NOT NULL,
    [Gebruikersnaam] nvarchar(50)  NOT NULL,
    [Email] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Logs'
CREATE TABLE [dbo].[Logs] (
    [LogId] int IDENTITY(1,1) NOT NULL,
    [Datum] datetime  NOT NULL,
    [Inhoud] nvarchar(max)  NOT NULL,
    [GebruikerGebruikersId] int  NOT NULL,
    [SociaalMedium] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'SociaalMediums'
CREATE TABLE [dbo].[SociaalMediums] (
    [SocialId] int IDENTITY(1,1) NOT NULL,
    [Sociaalmedium] nvarchar(50)  NOT NULL,
    [GebruikersnaamSM] nvarchar(50)  NULL,
    [WachtwoordSM] nvarchar(50)  NULL
);
GO

-- Creating table 'Autorisaties'
CREATE TABLE [dbo].[Autorisaties] (
    [AutorisatieId] int IDENTITY(1,1) NOT NULL,
    [GebruikerGebruikersId] int  NOT NULL,
    [SociaalMedium_SocialId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [GebruikersId] in table 'Gebruikers'
ALTER TABLE [dbo].[Gebruikers]
ADD CONSTRAINT [PK_Gebruikers]
    PRIMARY KEY CLUSTERED ([GebruikersId] ASC);
GO

-- Creating primary key on [LogId] in table 'Logs'
ALTER TABLE [dbo].[Logs]
ADD CONSTRAINT [PK_Logs]
    PRIMARY KEY CLUSTERED ([LogId] ASC);
GO

-- Creating primary key on [SocialId] in table 'SociaalMediums'
ALTER TABLE [dbo].[SociaalMediums]
ADD CONSTRAINT [PK_SociaalMediums]
    PRIMARY KEY CLUSTERED ([SocialId] ASC);
GO

-- Creating primary key on [AutorisatieId] in table 'Autorisaties'
ALTER TABLE [dbo].[Autorisaties]
ADD CONSTRAINT [PK_Autorisaties]
    PRIMARY KEY CLUSTERED ([AutorisatieId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [GebruikerGebruikersId] in table 'Logs'
ALTER TABLE [dbo].[Logs]
ADD CONSTRAINT [FK_GebruikerLog]
    FOREIGN KEY ([GebruikerGebruikersId])
    REFERENCES [dbo].[Gebruikers]
        ([GebruikersId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GebruikerLog'
CREATE INDEX [IX_FK_GebruikerLog]
ON [dbo].[Logs]
    ([GebruikerGebruikersId]);
GO

-- Creating foreign key on [GebruikerGebruikersId] in table 'Autorisaties'
ALTER TABLE [dbo].[Autorisaties]
ADD CONSTRAINT [FK_GebruikerAutorisatie]
    FOREIGN KEY ([GebruikerGebruikersId])
    REFERENCES [dbo].[Gebruikers]
        ([GebruikersId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GebruikerAutorisatie'
CREATE INDEX [IX_FK_GebruikerAutorisatie]
ON [dbo].[Autorisaties]
    ([GebruikerGebruikersId]);
GO

-- Creating foreign key on [SociaalMedium_SocialId] in table 'Autorisaties'
ALTER TABLE [dbo].[Autorisaties]
ADD CONSTRAINT [FK_AutorisatieSociaalMedium]
    FOREIGN KEY ([SociaalMedium_SocialId])
    REFERENCES [dbo].[SociaalMediums]
        ([SocialId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AutorisatieSociaalMedium'
CREATE INDEX [IX_FK_AutorisatieSociaalMedium]
ON [dbo].[Autorisaties]
    ([SociaalMedium_SocialId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------